package model.ability;

import java.util.Iterator;

import model.map.MapPoint;
import model.map.MapPointTreeNode;

/**
 * Placement algorithm which creates a circular tree of points
 * from the caster's current position.
 * @author Zachary
 */
public class Radial extends PlacementAlgorithm {

	@Override
	public MapPointTreeNode calculateDisplacementSet(MapPoint direction, int range) {
		if(!MapPoint.isValidDirection(direction))
			return null;
		
		MapPointTreeNode head = new MapPointTreeNode(ORIGIN);
		Cone cone = new Cone();
	
		MapPoint currentDirection = direction;
		
		// spawn and add the six cones that will comprise the radial tree
		for(int i = 1;i<=MapPoint.NUMDIRECTIONS;i++){
			MapPointTreeNode coneHead = cone.calculateDisplacementSet(currentDirection, range);
			Iterator<MapPointTreeNode> iter = coneHead.createChildIter();
			MapPointTreeNode firstConeChild = iter.next();
			head.addChild(firstConeChild);
			currentDirection = MapPoint.getNextClockWiseDirection(currentDirection);
		}
		
		return head;
	}

}
